package com.mind.invoice.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mind.common.annotation.Log;
import com.mind.common.web.controller.BaseController;
import com.mind.common.core.domain.AjaxResult;
import com.mind.common.enums.BusinessType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.mind.invoice.domain.AjRuleType;
import com.mind.invoice.service.IAjRuleTypeService;
import com.mind.common.utils.poi.ExcelUtil;
import com.mind.common.web.page.TableDataInfo;

/**
 * 规则分类Controller
 * 
 * @author xp
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/invoice/type")
@Tag(name = "规则分类管理", description = "规则分类管理")
public class AjRuleTypeController extends BaseController
{
    @Autowired
    private IAjRuleTypeService ajRuleTypeService;

    /**
     * 查询规则分类列表
     */
    @PreAuthorize("@ss.hasPermi('invoice:type:list')")
    @GetMapping("/list")
    @Operation(summary = "查询规则分类列表", description = "查询规则分类列表")
    public TableDataInfo list(AjRuleType ajRuleType)
    {
        startPage();
        List<AjRuleType> list = ajRuleTypeService.selectAjRuleTypeList(ajRuleType);
        return getDataTable(list);
    }

    /**
     * 导出规则分类列表
     */
    @PreAuthorize("@ss.hasPermi('invoice:type:export')")
    @Log(title = "规则分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出规则分类列表", description = "查询规则分类列表")
    public void export(HttpServletResponse response, AjRuleType ajRuleType)
    {
        List<AjRuleType> list = ajRuleTypeService.selectAjRuleTypeList(ajRuleType);
        ExcelUtil<AjRuleType> util = new ExcelUtil<AjRuleType>(AjRuleType.class);
        util.exportExcel(response, list, "规则分类数据");
    }

    /**
     * 获取规则分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('invoice:type:query')")
    @GetMapping(value = "/{id}")
    @Operation(summary = "获取规则分类详细信息", description = "获取规则分类详细信息")
    public AjaxResult getInfo(@Parameter(description ="规则分类Id",required=true) @PathVariable("id") Long id)
    {
        return success(ajRuleTypeService.selectAjRuleTypeById(id));
    }

    /**
     * 新增规则分类
     */
    @PreAuthorize("@ss.hasPermi('invoice:type:add')")
    @Log(title = "规则分类", businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增规则分类", description = "新增规则分类")
    public AjaxResult add(@RequestBody AjRuleType ajRuleType)
    {
        return toAjax(ajRuleTypeService.insertAjRuleType(ajRuleType));
    }

    /**
     * 修改规则分类
     */
    @PreAuthorize("@ss.hasPermi('invoice:type:edit')")
    @Log(title = "规则分类", businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改规则分类", description = "修改规则分类")
    public AjaxResult edit(@RequestBody AjRuleType ajRuleType)
    {
        return toAjax(ajRuleTypeService.updateAjRuleType(ajRuleType));
    }

    /**
     * 删除规则分类
     */
    @PreAuthorize("@ss.hasPermi('invoice:type:remove')")
    @Log(title = "规则分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @Operation(summary = "删除规则分类", description = "删除规则分类")
    public AjaxResult remove(@Parameter(description ="规则分类Id",required=true) @PathVariable Long[] ids)
    {
        return toAjax(ajRuleTypeService.deleteAjRuleTypeByIds(ids));
    }
}
